package com.hongruan.action.Blob;

import java.io.IOException;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.hongruan.action.BaseAction;
import com.hongruan.model.ResultStatusModel;
import com.hongruan.service.BlobService;

@Controller("BlobAction")
@Scope("prototype")
public class BlobAction extends BaseAction {

	private static final long serialVersionUID = 3098123134348030L;

	private static Logger logger = Logger.getLogger(BlobAction.class);

	@Resource
	private BlobService blobService;
	private String colname;
	private String nsrxx;
	private int width;
	private int height;

	public void getImage() {
		logger.info("blob getImage() begin");
		ResultStatusModel result = new ResultStatusModel();
		byte[] bs = this.blobService.getImage(colname, nsrxx,width, height);
		if(bs != null){
			try {
				ServletActionContext.getResponse().getOutputStream().write(bs);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}else{
			result.setSuccess(false);
		}
	}

	public String getColname() {
		return colname;
	}

	public void setColname(String colname) {
		this.colname = colname;
	}

	public String getNsrxx() {
		return nsrxx;
	}

	public void setNsrxx(String nsrxx) {
		this.nsrxx = nsrxx;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}
	
}
